var mongoose = require('mongoose')

var db = mongoose.createConnection('mongodb://127.0.0.1:27017/talkApp',{ useNewUrlParser: true, useUnifiedTopology: true ,useFindAndModify:false});
db.on('error',console.error.bind(console,'connect error:'));
db.once('open',function(){
  //it is connected!
  console.info('连接数据库 [talkApp] 成功');
})

//如果有以下警告：
// DeprecationWarning: Listening to events on the Db class has been deprecated and will be removed in the next major version.
// 解决方法：（该警告可以安全忽略）
// npm uninstall mongoose
// npm install mongoose@5.11.15
// 网址：https://stackoverflow.com/questions/66190532/deprecationwarning-listening-to-events-on-the-db-class-has-been-deprecated-and/66199780

module.exports = db;